/***************************** BEGIN LICENSE BLOCK ***************************

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/MPL-1.1.html
 
 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the License.
 
 The Original Code is the "EO-SPS Framework".
 
 The Initial Developer of the Original Code is Spotimage S.A.
 Portions created by the Initial Developer are Copyright (C) 2007
 the Initial Developer. All Rights Reserved.
 
 Contributor(s): 
    Alexandre Robin <alexandre.robin@spotimage.fr>
 
******************************* END LICENSE BLOCK ***************************/

package com.spotimage.eosps;

import org.w3c.dom.Element;
import org.vast.ogc.gml.GMLException;
import org.vast.ogc.gml.GMLTimeWriter;
import org.vast.ows.OWSException;
import org.vast.ows.sps.SPSException;
import org.vast.ows.swe.SWERequestWriter;
import org.vast.xml.DOMHelper;


/**
* <p><b>Title:</b><br/>
* EO-SPS GetSensorAvailability Request Writer v2.0
* </p>
*
* <p><b>Description:</b><br/>
* Provides methods to generate an XML EO-SPS GetSensorAvailability
* request based on values contained in a GetSensorAvailabilityRequest object
* for version 2.0
* </p>
*
* <p>Copyright (c) 2010</p>
* @author Alexandre Robin <alexandre.robin@spotimage.fr>
* @date July 19, 2010
* @version 1.0
*/
public class GetSensorAvailabilityRequestWriterV20 extends SWERequestWriter<GetSensorAvailabilityRequest>
{
	private GMLTimeWriter gmlWriter = new GMLTimeWriter("3.2");
	
	
	/**
	 * KVP Request
	 */
	@Override
	public String buildURLQuery(GetSensorAvailabilityRequest request) throws OWSException
	{
		throw new SPSException(noKVP + "SPS 2.0 " + request.getOperation());
	}


	/**
	 * XML Request
	 */
	@Override
	public Element buildXMLQuery(DOMHelper dom, GetSensorAvailabilityRequest request) throws OWSException
	{
		dom.addUserPrefix("eosps", EOConstants.EOT_NAMESPACE);

		// root element
		Element rootElt = dom.createElement("eosps:" + request.getOperation());
		addCommonXML(dom, rootElt, request);

		// sensorID
		dom.setElementValue(rootElt, "eosps:sensor", request.getSensorID());
		
		// requestPeriod
		try
		{
			Element timeElt = gmlWriter.writeTime(dom, request.getRequestPeriod());
			Element parentElt = dom.addElement(rootElt, "eosps:requestPeriod");
			parentElt.appendChild(timeElt);
		}
		catch (GMLException e)
		{
			throw new SPSException(e.getMessage(), e);
		}	
	
		return rootElt;
	}
}